<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.fc.util.*" %>
<%@ page import="com.fc.model.Admin" %>
<%@ page import="com.fc.control.AdminControl" %>
<%@ include file="../login/login_check.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>admin_add_do</title>
</head>
<body>
<%
      request.setCharacterEncoding("UTF-8");
      String user_name = ParamUtil.getString(request,"user_name");   
      String user_pwd2 = ParamUtil.getString(request,"user_pwd2");
  	  String user_pwd3 = ParamUtil.getString(request,"user_pwd3");
  	  String idcard = ParamUtil.getString(request,"idcard");
  	  String phone = ParamUtil.getString(request,"phone");
  	  int role =  ParamUtil.getInt(request,"role");
  	  int sex =  ParamUtil.getInt(request,"sex");
  	  
  	  //AdminControl ac = new AdminControl();
      Admin admin = new Admin();
      admin.setUsername(user_name);
	  admin.setPassword(user_pwd2);
	  admin.setIdcard(idcard);
	  admin.setPhone(phone);
	  admin.setRole(role);
	  admin.setSex(sex);
	  if(AdminControl.isUsername(user_name)){
         %>
	      <script language="javascript">
          alert("该用户名存在！");
          window.location.href="admin.jsp";
          </script>
        <%
      }
      else
      {
		  if(user_pwd2.equals(user_pwd3))
		 {
			if(AdminControl.addAdmin(admin))
			{
			    //session.removeAttribute("username");
				//session.removeAttribute("password");
	  		    //session.setAttribute("username",user_name); 
				//session.setAttribute("password",user_pwd2);
	  	%>
			    <script language="javascript">
  				alert("添加成功");
  				window.location.href="admin.jsp";
  				</script>
			<%
			} 
			else
			{ 
				%>
				<script language="javascript">
  				alert("添加失败");
  				history.back();
  				</script>
				<%
		    } 
	  	}
  		else 
  		{
	  		%>
			<script language="javascript">
  			alert("密码不一致");
  	        history.back();
	  		</script>
		<%
		}
	  }
        %>
</body>
</html>